package com.ll.module_translate.entity

/**
 * @Author: ll
 * @CreateTime: 2021/10/29 14:26
 */
 interface TResult<T> {
    data class Success(
        val from: String,
        val to: String,
        val trans_result: List<TransResult>
    ) : TResult<TranslateResult>

    data class Error(
        val error_code: String,
        val error_msg: String
    ) : TResult<TranslateResult>
}

inline fun <reified T> TResult<T>.isSuccess(
    success: (
        from: String,
        to: String,
        trans_result: List<TransResult>
    ) -> Unit
) {
    if (this is TResult.Success) {
        success.invoke(from,to,trans_result)
    }
}

inline fun <reified T> TResult<T>.isError(
    error: (
        error_code: String,
        error_msg: String
    ) -> Unit
) {
    if (this is TResult.Error) {
        error.invoke(error_code,error_msg)
    }
}